package com.example.dynamicschedule.service.impl;

import com.alibaba.fastjson.JSONObject;
import com.example.dynamicschedule.bean.CkOrderRecoveryData;
import com.example.dynamicschedule.dao.CkOrderRecoveryDataMapper;
import com.example.dynamicschedule.service.CkOrderRecoveryDataService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service
public class CkOrderRecoveryDataServiceImpl implements CkOrderRecoveryDataService {
    protected static final Logger logger = LoggerFactory.getLogger(CkOrderRecoveryDataServiceImpl.class);
    @Autowired
    private CkOrderRecoveryDataMapper ckOrderRecoveryDataMapper;

    @Override
    public PageInfo selectCkOrderRecoverlist(Map<String, Object> map) {
        logger.info("获取催记列表start---参数：param:" + map.toString());
        int page = Integer.parseInt(map.getOrDefault("page", "1").toString());
        int pageSize = Integer.parseInt(map.getOrDefault("pageSize", "10").toString());
        PageHelper.startPage(page, pageSize);
        List<CkOrderRecoveryData> list = ckOrderRecoveryDataMapper.selectRecoveryDataList(map);
        PageInfo pageInfo = new PageInfo<>(list);
        logger.info("获取催记列表end---result：pageInfo:" + pageInfo.toString());
        return pageInfo;
    }

    @Override
    public CkOrderRecoveryData getCkOrderrecoverById(long id) {
        logger.info("获取催记详情start---参数：id:" + id);
        CkOrderRecoveryData ckOrderRecoveryData=ckOrderRecoveryDataMapper.selectByPrimaryKey(id);
        logger.info("获取催记详情end---参数：result:" + JSONObject.toJSONString(ckOrderRecoveryData));
        return ckOrderRecoveryData;
    }

    @Override
    public void insertForeach(List<CkOrderRecoveryData> ckOrderRecoveryDataList) {
        ckOrderRecoveryDataMapper.insertForeach(ckOrderRecoveryDataList);
    }

    @Override
    public List<CkOrderRecoveryData> findByNotificationMethodAndDateTime(byte outbound, String yesterday) {
        logger.info("获取催收员成绩start---参数：outbound:" + outbound+",yesterday:"+yesterday);
        Map<String, Object> params = new HashMap<>();
        params.put("outbound",outbound);
        params.put("yesterday",yesterday);
        List<CkOrderRecoveryData> ckOrderRecoveryDataList= ckOrderRecoveryDataMapper.findByNotificationMethodAndDateTime(params);
        logger.info("获取催收员成绩end---参数：result:" + JSONObject.toJSONString(ckOrderRecoveryDataList));
        return ckOrderRecoveryDataList;

    }


    @Override
    public void updateForEach(List<CkOrderRecoveryData> mergeCkRecoverDataList) {
        ckOrderRecoveryDataMapper.updateForEach(mergeCkRecoverDataList);
    }

    @Override
    public List<CkOrderRecoveryData> selectBySerialNumbers(List<String> serialNumberList, String sendTime) {
        Map<String, Object> paramMap = new HashMap<>();
        paramMap.put("serialNumberList",serialNumberList);
        paramMap.put("sendTime",sendTime);
        return ckOrderRecoveryDataMapper.selectBySerialNumbers(paramMap);
    }

    @Override
    public void deleteForEach(List<CkOrderRecoveryData> intelligenceDivisionCkOrderRecoveryData) {
        ckOrderRecoveryDataMapper.deleteForEach(intelligenceDivisionCkOrderRecoveryData);
    }
}
